home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / mthreads.h < prev    next >
C/C++ Source or Header  |  1999-02-04  |  4KB  |  166 lines

  1. /* $Id: mthreads.h,v 1.2 1998/02/04 08:53:44 poliwoda Exp poliwoda $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.6
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. /*
  24.  * mthreads.h -- platform dependent thread support for Mesa 
  25.  *
  26.  * $Log$
  27.  *
  28.  * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu)
  29.  *                and Christoph Poliwoda (poliwoda@volumegraphics.com)
  30.  */
  31.  
  32.  
  33. /*
  34.  * If this file is accidentally included by a non-threaded build, 
  35.  * it should not cause the build to fail, or otherwise cause problems.
  36.  * In general, it should only be included when needed however.
  37.  */
  38. #ifdef THREADS
  39. /*
  40.  * It is an error not to select a specific threads API when compiling.
  41.  */
  42. #if !defined PTHREADS && !defined SOLARIS_THREADS && !defined WIN32
  43. #error One of PTHREADS, SOLARIS_THREADS or WIN32 must be defined.
  44. #endif
  45.  
  46.  
  47. /*
  48.  * Error messages which should be printed when our Mesa thread APIs fail
  49.  * for one reason or another.
  50.  */
  51. #define MESA_INIT_TSD_ERROR "Mesa: thread failed to allocate key for thread specific data"
  52. #define MESA_GET_TSD_ERROR "Mesa: thread failed to get thread specific data"
  53. #define MESA_SET_TSD_ERROR "Mesa: thread failed to set thread specific data"
  54.  
  55.  
  56. /*
  57.  * magic number for win32 and solaris threads equivalents of pthread_once
  58.  * This could probably be done better, but we haven't figured out how yet. 
  59.  */
  60. #define INITFUNC_CALLED_MAGIC 0xff8adc98
  61.  
  62.  
  63.  
  64.  
  65. /*
  66.  * POSIX threads. This should be your choice in the Unix world
  67.  * whenever possible.  When building with POSIX threads, be sure
  68.  * to any able any compiler flags which will cause the MT-safe
  69.  * libc (if one exists) to be used when linking, as well as any
  70.  * header macros for MT-safe errno, etc.  For Solaris, this is the -mt
  71.  * compiler flag.  On Solaris with gcc, use -D_REENTRANT to enable
  72.  * proper compiling for MT-safe libc etc.
  73.  */
  74. #ifdef PTHREADS
  75. #include <pthread.h> /* POSIX threads headers */
  76.  
  77. typedef struct {
  78.   pthread_key_t  key;
  79.   pthread_once_t once;
  80. } MesaTSD;
  81.  
  82. typedef pthread_mutex_t MesaMutex;
  83. typedef pthread_t MesaThread;
  84.  
  85. #endif /* PTHREADS */
  86.  
  87.  
  88.  
  89.  
  90. /*
  91.  * Solaris threads. Use only up to Solaris 2.4. 
  92.  * Solaris 2.5 and higher provide POSIX threads.
  93.  * Be sure to compile with -mt on the Solaris compilers, or 
  94.  * use -D_REENTRANT if using gcc.
  95.  */
  96. #ifdef SOLARIS_THREADS
  97. #include <thread.h>
  98.  
  99. typedef struct {
  100.   thread_key_t key;
  101.   mutex_t      keylock;
  102.   int          initfuncCalled;
  103. } MesaTSD;
  104.  
  105. typedef mutex_t MesaMutex;
  106. typedef thread_t MesaThread;
  107.  
  108. #endif /* SOLARIS_THREADS */
  109.  
  110.  
  111.  
  112.  
  113. /*
  114.  * Windows threads. Should work with Windows NT and 95. 
  115.  * IMPORTANT: Link with multithreaded runtime library when THREADS are
  116.  * used!
  117.  */
  118.  
  119. #ifdef WIN32
  120. #include <windows.h>
  121.  
  122. typedef struct {
  123.   DWORD key;
  124.   int   initfuncCalled;
  125. } MesaTSD;
  126.  
  127. typedef CRITICAL_SECTION MesaMutex;
  128. typedef HANDLE MesaThread;
  129.  
  130. #endif /* WIN32 */
  131.  
  132.  
  133.  
  134.  
  135. /*
  136.  * Platform independent thread specific data API. 
  137.  */
  138. void  MesaInitTSD(MesaTSD *);
  139. void* MesaGetTSD (MesaTSD *);
  140. void  MesaSetTSD (MesaTSD *, void *, void (*initfunc)(void));
  141.  
  142.  
  143. /* 
  144.  * The following APIs are preliminary.  They may be needed in 
  145.  * future versions of Mesa.  
  146.  */
  147. #if 0
  148.  
  149. /*
  150.  * Platform independent mutual exclusion lock API.
  151.  */
  152. void  MesaInitMutex    (MesaMutex *);
  153. void  MesaDestroyMutex (MesaMutex *);
  154. void  MesaLockMutex    (MesaMutex *);
  155. void  MesaUnlockMutex  (MesaMutex *);
  156.  
  157. /* 
  158.  * Platform independent thread management API.
  159.  */
  160. MesaThread  MesaCreateThread ((void*)(*)(void*), void*);
  161. void        MesaJoinThread   (MesaThread);
  162.  
  163. #endif 
  164.  
  165. #endif /* THREADS */
  166.